<?php
/* Zendvn : Ten thu muc 
 * Controller :  Ten thu muc 
 * Action : Ten file chay
 */
class Zendvn_Controller_Action extends Zend_Controller_Action{
    
    public function init() {
//        $template_path = TEMPLATE_PATH . "/admin/system";
//        $this->loadTemplate($template_path , 'template.ini', 'template');
    }
    
    protected function loadTemplate($template_path, $fileConfig = 'template.ini', $sectionConfig = 'template') {
		
        $filename = $template_path ."/". $fileConfig;
        $section = $sectionConfig;
        $config = new Zend_Config_Ini($filename, $section );
        $config = $config->toArray();
        
        $baseUrl = $this->_request->getBaseUrl();
//        echo '<br>' . $baseUrl;
        
        $templateUrl = $baseUrl . $config['url'];
        $cssUrl = $templateUrl . $config['dirCss'];
        $jsUrl = $templateUrl . $config['dirJs'];
        $imgUrl = $templateUrl . $config['dirImg'];
        
        //Nạp Title cho layout
        $this->view->headTitle($config['title']);
        
        
        //Nạp các thẻ Meta vào layout
        if(count($config['metaHttp']) > 0){
            foreach ($config['metaHttp'] as $key => $value) {
                $tmp = explode("|", $value);
                $this->view->headMeta()->appendHttpEquiv($tmp[0] , $tmp[1]);
            }
        }
        if(count($config['metaName']) > 0){
            foreach ($config['metaName'] as $key => $value) {
                $tmp = explode("|", $value);
                $this->view->headMeta()->appendName($tmp[0] , $tmp[1]);
            }
        }
        
        //Nạp các tập tin Css vào layout
        if(count($config['fileCss']) > 0){
            foreach ($config['fileCss'] as $key => $css) {
                $this->view->headLink()->appendStylesheet($cssUrl . $css , 'screen');
            }
        }
        
        //Nạp các tập tin Js vào layout
        if(count($config['fileJs']) > 0){
            foreach ($config['fileJs'] as $key => $js) {
                $this->view->headScript()->appendFile($jsUrl . $js , 'text/javascript');
            }
        }
        $this->view->templateUrl = $templateUrl;
        $this->view->cssUrl = $cssUrl;
        $this->view->jsUrl = $jsUrl;
        $this->view->imgUrl = $imgUrl;
        
        
        $options = array('layoutPath' => $template_path,'layout'=>$config['layout']);
        Zend_Layout::startMvc($options);
    }
    
}
